package cur.nature.component.quartz.config;

import cur.nature.framework.core.log.LOG;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author wujian
 * @date 2021/08/28
 */
@Component
@Order(value = 1)
@ConditionalOnProperty( value = {"cur.component.quartz.enable"})
public class QuartzTriggerListener implements TriggerListener {

    @Override
    public String getName() {
        return "scheduleTriggerListener";
    }

    @Override
    public void triggerFired(Trigger trigger, JobExecutionContext context) {
        LOG.info("执行ScheduleTriggerListener: triggerFired");
    }

    @Override
    public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
//        LOG.info("执行ScheduleTriggerListener: vetoJobExecution");
        return false;
    }

    @Override
    public void triggerMisfired(Trigger trigger) {
//        LOG.info("执行ScheduleTriggerListener: triggerMisfired");
    }

    @Override
    public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
        LOG.info("执行ScheduleTriggerListener: triggerComplete");
    }
}
